home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / tcpip / misc / tnc1stuf.lzh / NET_TNC.ARC / KISSLDR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-06-12  |  5.0 KB  |  201 lines

  1. {$U+}
  2. program loadkiss;
  3. type
  4.     String19=String[19];
  5. var
  6.    hexfile : string[12];
  7.    f1      : text;
  8.     Port,Baud,StopBits,DataBits,Par: Integer;
  9.     Message: String[80];
  10.  
  11.  
  12.   Type
  13.     __RegisterSet=Record case Integer of
  14.                   1: (AX,BX,CX,DX,BP,DI,SE,DS,ES,Flags: Integer);
  15.                   2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  16.                 end;
  17.     __ParityType=(None,Even,Odd);
  18.  
  19.   var
  20.     __Regs: __RegisterSet;
  21.     InError,OutError: Array [1..2] of Byte;
  22.  
  23.   procedure __Int14(PortNumber,Command,Parameter: Integer);
  24.   { do a BIOS COM driver interrupt }
  25.  
  26.     begin
  27.       with __Regs do
  28.        begin
  29.         DX:=PortNumber-1;
  30.         AH:=Command;
  31.         AL:=Parameter;
  32.         Flags:=0;
  33.         Intr($14,__Regs);
  34.        end;
  35.     end;
  36.  
  37.  
  38.   procedure SetSerial(PortNumber,BaudRate,StopBits,DataBits: Integer;
  39.                       Parity: __ParityType);
  40.   { Set serial parameters on a COM port }
  41.  
  42.     var
  43.       Parameter: Integer;
  44.  
  45.     begin
  46.       case BaudRate of
  47.         110: BaudRate:=0;
  48.         150: BaudRate:=1;
  49.         300: BaudRate:=2;
  50.         600: BaudRate:=3;
  51.         1200: BaudRate:=4;
  52.         2400: BaudRate:=5;
  53.         4800: BaudRate:=6;
  54.         else BaudRate:=7; { Default to 9600 baud }
  55.        end;
  56.       if StopBits=2 then StopBits:=1
  57.       else StopBits:=0; { Default to 1 stop bit }
  58.       if DataBits=7 then DataBits:=2
  59.       else DataBits:=3; { Default to 8 data bits }
  60.       Parameter:=(BaudRate Shl 5)+(StopBits Shl 2)+DataBits;
  61.       case Parity of
  62.         Odd: Parameter:=Parameter+8;
  63.         Even: Parameter:=Parameter+24;
  64.         else; { Default to no parity }
  65.        end;
  66.       __Int14(PortNumber,0,Parameter);
  67.     end;
  68.  
  69.  
  70.   Function SerialStatus(PortNumber: Integer): Integer;
  71.   { Return the status of a COM port }
  72.  
  73.     begin
  74.       __Int14(PortNumber,3,0);
  75.       SerialStatus:=__Regs.AX;
  76.     end;
  77.  
  78.  
  79.   procedure __OutPort1(C: Byte);
  80.   { Called by Write to Aux or Usr when assigned to COM1 }
  81.  
  82.     begin
  83.       while (SerialStatus(1) and $30)=0 do ;
  84.       __Int14(1,1,C);
  85.       OutError[1]:=OutError[1] Or (__Regs.AH and $8E);
  86.     end;
  87.  
  88.  
  89.   procedure __OutPort2(C: Byte);
  90.   { Called by Write to Aux or Usr when assigned to COM2 }
  91.  
  92.     begin
  93.       while (SerialStatuS(2) and $30)=0 do ;
  94.       __Int14(2,1,C);
  95.       OutError[2]:=OutError[2] Or (__Regs.AH and $8E);
  96.     end;
  97.  
  98.  
  99.   Function __InPort1: Char;
  100.   { Called by Read from Aux or Usr when assigned to COM1 }
  101.  
  102.     begin
  103.       __Int14(1,2,0);
  104.       __InPort1:=Chr(__Regs.AL);
  105.       InError[1]:=InError[1] Or (__Regs.AH and $8E);
  106.     end;
  107.  
  108.  
  109.   Function __InPort2: Char;
  110.   { Called by Read from Aux or Usr when assigned to COM2 }
  111.  
  112.     begin
  113.       __Int14(2,2,0);
  114.       __InPort2:=Chr(__Regs.AL);
  115.       InError[2]:=InError[2] Or (__Regs.AH and $8E);
  116.     end;
  117.  
  118.  
  119.   procedure __AssignPort(PortNumber: Integer; var InPtr,OutPtr: Integer);
  120.   { Assign either Aux or Usr to either COM1 or COM2 }
  121.  
  122.     begin
  123.       if PortNumber=2 then
  124.        begin
  125.         OutPtr:=Ofs(__OutPort2);
  126.         InPtr:=Ofs(__InPort2);
  127.        end
  128.       else { Default to port 1 }
  129.        begin
  130.         OutPtr:=Ofs(__OutPort1);
  131.         InPtr:=Ofs(__InPort1);
  132.        end;
  133.       InError[PortNumber]:=0;
  134.       OutError[PortNumber]:=0;
  135.     end;
  136.  
  137.  
  138.   procedure AssignAux(PortNumber: Integer);
  139.   { Assign Aux to either COM1 or COM2 }
  140.  
  141.     begin
  142.       __AssignPort(PortNumber,AuxInPtr,AuxOutPtr);
  143.     end;
  144.  
  145.  
  146.   procedure AssignUsr(PortNumber: Integer);
  147.   { Assign Usr to either COM1 or COM2 }
  148.  
  149.  
  150.     begin
  151.       __AssignPort(PortNumber,UsrInPtr,UsrOutPtr);
  152.     end;
  153.  
  154.  
  155.   Function Binary(V: Integer): String19;
  156.  
  157.     var
  158.       I: Integer;
  159.       B: Array [0..3] of String[4];
  160.  
  161.     begin
  162.       For I:=0 To 15 do
  163.         if (V and (1 Shl (15-I)))<>0 then B[I Div 4][(I Mod 4)+1]:='1'
  164.         else B[I Div 4][(I Mod 4)+1]:='0';
  165.       For I:=0 To 3 do B[I][0]:=Chr(4);
  166.       Binary:=B[0]+' '+B[1]+' '+B[2]+' '+B[3];
  167. end; 
  168. begin
  169.     Write('What is the name of the hex file you wish to load:    ');
  170.     Readln(hexfile);
  171.     Assign(f1,hexfile);
  172.     Reset(f1);
  173.     Write('Enter port number:                    ');
  174.     ReadLn(Port);
  175.     AssignUsr(Port);
  176.     Write('Enter baud rate:                      ');
  177.     ReadLn(Baud);
  178.     Write('Enter stop bits:                      ');
  179.     ReadLn(StopBits);
  180.     Write('Enter data bits:                      ');
  181.     ReadLn(DataBits);
  182.     Write('Enter parity (0=none, 1=even, 2=odd): ');
  183.     ReadLn(Par);
  184.     SetSerial(Port,Baud,StopBits,DataBits,__ParityType(Par));
  185.     ClrScr;
  186.     GotoXY(20,12);
  187.     Writeln('loading file |',hexfile,'| into tnc');
  188.     Write(Usr,Chr(5));
  189.     while not(eof(f1)) do
  190.     begin
  191.        ReadLn(f1,Message);
  192.        WriteLn(Usr,Message);
  193.        Writeln(Message);
  194.     end;
  195.     WriteLn('OutError[',Port,']: ',Binary(OutError[Port]));
  196.     WriteLn('SerialStatus(',Port,'): ',Binary(SerialStatus(Port)));
  197.  
  198.     Writeln;Writeln;Writeln('  Kiss Tnc loaded');
  199. end.
  200.  
  201.